<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>专家人员列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <!-- <link rel="stylesheet" href="/static/css/weadmin.css">-->
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form" style="margin-top: 20px;">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 100px;">用户登陆名：</label>
            <div class="layui-input-inline">
                <input type="text" name="userName" id="userName" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 100px;">真实姓名：</label>
            <div class="layui-input-inline">
                <input type="text" name="realName" id="realName" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 100px;">身份证号码：</label>
            <div class="layui-input-inline">
                <input type="text" name="userCard" id="userCard" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 100px;">所在单位：</label>
            <div class="layui-input-inline">
                <input type="text" name="orgName" id="orgName" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <div class="layui-input-inline">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="formDemo">搜索</button>
                <button class="layui-btn layui-btn-sm" >清空</button>
            </div>
        </div>

    </div>
</form>
<table class="layui-hide" id="dataList" lay-filter="dataList"></table>

<script type="text/html" id="toolbarOrg">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加账户</button>
        <button class="layui-btn layui-btn-sm" lay-event="del">批量删除</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    {{# if(d.status==0 || d.status==1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-disabled">启用</a>
    {{# }else if(d.status==2){ }}
    <a class="layui-btn layui-btn-xs" lay-event="statuBtn">禁用</a>
    {{# }else if(d.status==3){ }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="statuBtn">启用</a>
    {{# } }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <!--
     <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    -->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="changePass">重置密码</a>
</script>

<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    var configureCom = {};
    layui.use(['jquery', 'configureCom', 'configure', 'sessionFun', 'table', 'matchDict','jsDictFile'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var matchDict = layui.matchDict;

        configureCom = layui.configureCom;
        var cols = [[
            {type: 'checkbox'},
            {title: '序号', type: 'numbers'},
            {field: 'userName', width:180, title: '登录名'},
            {field: 'userCard', width:180,title: '身份证号码'},
            {field: 'realName', width:180,title: '真实姓名'},

            {
                field: '', title: '所在单位',width:250, templet: function (d) {
                    var html = '';
                    $(d.orgList).each(function (index, item) {
                        if (!index) {
                            html += item.orgName
                        } else {
                            html += ',' + item.orgName
                        }
                    });
                    return html;
                }
            },

            {field: 'contact', width:160,title: '联系方式'},
            {
                field: '', title: '用户角色',width:200, templet: function (d) {
                    var html = '';
                    $(d.roleList).each(function (index, item) {
                        if (!index) {
                            html += item.roleName
                        } else {
                            html += ',' + item.roleName
                        }
                    });
                    return html;
                }
            },
            {
                field: '', title: '用户状态', width:150,templet: function (d) {
                    return matchDict.name(d.status, 'ORG_STATUS');
                }
            },
            {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 250}
        ]];
        configureCom.tableRender(configure.EXPERT_LIST_HTTP, {}, cols, 'dataList', 10, 'full', 'toolbarOrg');
        configureCom.tableSearch();
        //头工具栏事件
        table.on('toolbar(dataList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            sessionFun.remove(configure.SESSION_LIST_DATA);
            switch (obj.event) {
                case 'add':
                    editItem('账户添加', configure.USER_SAVE_HTTP);
                    break;
                case 'del':
                    var data = checkStatus.data;
                    if (!data.length) {
                        top.layer.alert('请您至少选择一条数据后再提交！');
                        return false;
                    }
                    top.layer.confirm('您真的要删除选中的数据吗？', function (index, layero) {
                        top.layer.close(index);
                        var ids = '';
                        $(data).each(function (index, item) {
                            if (!index) {
                                ids = item.roleId;
                            } else {
                                ids += ',' + item.roleId;
                            }
                        });
                        deleteFun(ids);
                    });
                    break;
            }
        });
        //每行操作
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.SESSION_LIST_DATA, data);
            if (obj.event === 'del') {//查看详情
                deleteFun(data.roleId);
            } else if (obj.event === 'edit') {
                editItem('账户修改', configure.USER_UPDATE_HTTP)
            } else if (obj.event === 'statuBtn') {
                var status=data.status;
                var msg="";
                if(status==2){
                    msg="您真的要禁用这个账户吗？";
                }else{
                    msg="您真的要启用这个账户吗？";
                }
                top.layer.confirm(msg, function (index) {
                    top.layer.close(index);
                    configureCom.postDataAjax(configure.COM_USER_STATUS_HTTP, {userId: data.userId}).then(function (res) {
                        if (res.code == 0) {
                            configureCom.tableReload(true);
                        } else {
                            top.layer.alert('设置失败！')
                        }
                    });
                });
            }else if (obj.event === 'changePass') {
                msg="您真的要重置账户密码吗？";
                top.layer.confirm(msg, function (index) {
                    top.layer.close(index);
                    configureCom.postDataAjax(configure.USER_RESETPW_HTTP, {userId: data.userId}).then(function (res) {
                        if (res.code == 0) {
                            configureCom.tableReload(true);
                        } else {
                            top.layer.alert('重置失败！')
                        }
                    });
                });


            }
        });

        function deleteFun(ids) {
            configureCom.postDataAjax(configure.USER_DELETE_HTTP, {roleIds: ids}).then(function (res) {
                if (res.code == 0) {
                    top.layer.msg('删除成功！');
                    configureCom.tableReload(true);
                } else {
                    top.layer.alert('删除失败！');
                }
            });
        }

        //新增或修改字典详情
        function editItem(title, url) {
            top.layer.open({
                type: 2,
                title: title,
                area: configureCom.Psize1,
                content: configureCom.nocache(configure.USER_DETAIL_HTML),
                btn: ['保存'],
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    var data = iframeWin.getData();
                    console.log(data);
                    configureCom.postDataAjax(url, data).then(function (res) {
                        if (res.code == 0) {
                            top.layer.close(index);
                            top.layer.msg('保存成功！');
                            configureCom.tableReload(true);
                        } else {
                            top.layer.alert('保存失败！');
                        }
                    });
                }
            });
        }
    });

</script>
</body>
</html>